package br.uece.tcc.flathead.jxta;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Observable;
import java.util.Observer;

import net.jxta.endpoint.Message;
import net.jxta.pipe.PipeMsgEvent;
import net.jxta.pipe.PipeMsgListener;

/*
 * BroadcastListener
 * Created on 30/06/2005
 * 
 */

/**
 * @author edward ribeiro
 * 
 */
public class FhJxtaBroadcastListener extends Observable implements PipeMsgListener {
	
	private Hashtable observers = new Hashtable();
	
	public void addObserver(Observer observer) {		
		observers.put(observer, observer);
	}
		
	public void pipeMsgEvent(PipeMsgEvent event) {
		
		Message msg = event.getMessage();
		String message = msg.getMessageElement(FhJxtaBroadcast.PUBLIC).toString();		
		if (observers.size() > 0) {			
			Enumeration en = observers.elements();
			while (en.hasMoreElements()) {
				Observer observer = (Observer) en.nextElement();
				observer.update(this, message);				
			}
		}
	}
}
